// return:id=1&name=halo
export function getParamUrl() {
  const hash = window.location.hash;
  if (hash.includes("#")) {
    const last = hash.substr(1);
    if (last.includes("?")) {
      return last.split("?")[1];
    }
    return null;
  }
  return null;
}

// 获取URL中的参数
export function getParam(paramKey: string) {
  //如:id=1&name=halo
  const paramUrl = getParamUrl();
  if (paramUrl == null) {
    return null;
  }
  const params = paramUrl.split("&");
  for (let i = 0; i < params.length; i++) {
    const param = params[i];
    if (param.includes("=")) {
      const kv = param.split("=");
      const key = kv[0];
      const val = kv[1];
      if (key === paramKey) {
        return val;
      }
    }
  }
  return null;
}

// 检测当前环境是网页还是手机
export function isMobile(): boolean {
  return window.matchMedia("only screen and (max-width: 768px)").matches;
}
